/*
 * @Description:
 * @Author: shilinzhou
 * @Date: 2024-02-02 10:18:45
 * @LastEditors: shilinzhou
 * @LastEditTime: 2024-03-25 16:03:51
 */
import QRequest from '@/service/index';
import { generateNameToLevel } from '@/config/constant';
import {
    AddParams,
    InformationResponse,
    MaterialsResponse,
    OrderListParams,
    OrderListRecord,
    OrderListResponse,
    ProcessResponse
} from './model/type';
import { ParamsPage } from '@/api/common/type';

/**
 * @: 获取需求订单列表
 */
export const doGetOrderList = (data: OrderListParams) => {
    return QRequest.post<OrderListResponse>(`/orderInformation`, data);
};

/**
 * @: 获取物料编码列表
 */
export const doGetMaterials = (params: Partial<MaterialsResponse>) => {
    return QRequest.get<MaterialsResponse[]>(`/material/getSupplierMaterials`, {
        params,
        headers: {
            hideLoading: 1
        }
    });
};

/**
 * @: 获取客户信息列表
 */
export const doGetInformation = (params: Partial<InformationResponse>) => {
    return QRequest.get<InformationResponse[]>(`/customerInformation/getCustomerInformation`, {
        params,
        headers: {
            hideLoading: 1
        }
    });
};

/**
 * @: 获取工艺查询列表
 */
export const doGetCraftList = (params: ParamsPage & { materialCode: string }) => {
    return QRequest.get<ProcessResponse>(`/process/route/order/technological/process`, {
        params,
        headers: {
            loadingTarget: `#${generateNameToLevel('1')}`
        }
    });
};

/**
 * @: 修改订单数据
 */
export const doUpdateOrder = (data: OrderListRecord) => {
    return QRequest.put(`/orderInformation/update`, data);
};

/**
 * @: 更新订单优先级
 */
export const doUpdateOrderPriority = (data: { id: number; orderPriority: number }) => {
    return QRequest.put(`/orderInformation/update/increment`, data, {
        headers: {
            hideLoading: 1
        }
    });
};

/**
 * @: 添加订单数据
 */
export const doAddOrder = (data: AddParams) => {
    return QRequest.post(`/orderInformation/create`, data, {
        headers: {
            hideLoading: 1
        }
    });
};
